package com.yksj.healthtalk.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.yksj.healthtalk.entity.SalonIncomeDetailEntity;
import com.yksj.healthtalk.ui.R;

public class SalonInComeDetailAdapter extends BaseAdapter {
	private Context context;
	private ArrayList<SalonIncomeDetailEntity> entities;
	private ViewHolder holder;
	private String pic;
	private String file;
	private String voice;
	private String date;
	private char [] c = new char[5];
	private int money;
	private String day_ticket;
	private String month_ticket;
//	102110 沙龙日票赚取
//	102120	 沙龙月票赚取
//	102130	 共享视频赚取
//	102140	 共享图片赚取
//	102150	 共享文件赚取
//	102160	 共享音频赚取
	public SalonInComeDetailAdapter(Context context , ArrayList<SalonIncomeDetailEntity> entities) {
		this.context = context;
		this.entities = entities;
		day_ticket = context.getResources().getString(R.string.detail_day_ticket);
		pic = context.getResources().getString(R.string.detail_pic);	
		file = context.getResources().getString(R.string.detail_file);
		voice = context.getResources().getString(R.string.detail_voice);
		month_ticket = context.getResources().getString(R.string.detail_month_ticket);
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return entities.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return null;
	}

	
//	public String getDate(){
//		return this.date;
//	}
	
	public int getMoney(){
		for (int i = 0; i < this.entities.size(); i++) {
			money = money + Integer.valueOf(entities.get(i).getChangeNum());
			this.date = entities.get(i).getChangeTime().substring(0, 8);
		}
		return this.money;
	}
	
	public void setMoney(int money){
		
		this.money = money;
	}
	
	
	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if(convertView==null){
			holder=new ViewHolder();
			convertView=LayoutInflater.from(context).inflate(R.layout.salon_income_detail_item, null);
			holder.file_count=(TextView)convertView.findViewById(R.id.file_count);
			holder.file_money=(TextView)convertView.findViewById(R.id.file_money);
			convertView.setTag(holder);
		}else{
			holder = (ViewHolder) convertView.getTag();
		}
		//money
		holder.file_money.setText(entities.get(position).getChangeNum());
		
		//截取时间
		 String str = entities.get(position).getChangeTime();
		 str = str.substring(str.length()-6);
		 for (int i = 0; i < str.length()+1; i++) {
			 if (i==2) {
				c[2]=':';
			}else if(i<2){
				 c[i] = str.charAt(i);
			}else if (i<5){
				 c[i] = str.charAt(i-1);
			}
		}
		//显示的内容
		switch (Integer.valueOf(entities.get(position).getTypeDetail())) {
		case 102110://沙龙日票赚取
			holder.file_count.setText(String.format(day_ticket,String.copyValueOf(c)));
			break;
		case 102120://沙龙月票赚取
			holder.file_count.setText(String.format(month_ticket,String.copyValueOf(c)));
			break;
		case 102140	 ://共享图片赚取
			holder.file_count.setText(String.format(pic, String.copyValueOf(c)));
			break;
		case 102150	 	:// 共享文件赚取
			holder.file_count.setText(String.format(file,String.copyValueOf(c)));
			break;
		case 102160	 ://共享音频赚取
			holder.file_count.setText(String.format(voice,String.copyValueOf(c)));
			break;
		default:
			break;
		}
		return convertView;
	}
	
	class ViewHolder{
		TextView file_count;
		TextView file_money;
	}
	
}
